package com.zretc.controller;

import com.zretc.entity.ResponseResult;
import com.zretc.entity.UserInfo;
import com.zretc.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.annotation.MultipartConfig;
import java.util.Map;

/**
 * @author 周文涛
 * 获取登录后的信息
 */
@RestController
@RequestMapping("/login/user")
@MultipartConfig
public class LoginController {

    @Autowired
    private UserInfoService userInfoService;

    // 获取登录用户的信息
    @GetMapping("/")
    public UserDetails getLoginUser(){
        return userInfoService.getLoginUser();
    }

    // 修改用户信息
    @PutMapping("/info")
    public ResponseResult updateInfo(@RequestBody Map<String,Object> objectMap){
        return userInfoService.updateUserInfo(objectMap);
    }
    // 修改密码
    @PutMapping("/password")
    public ResponseResult updatePassword(@RequestBody Map<String,Object> objectMap){
        return userInfoService.updatePassword(objectMap);
    }
    // 修改头像
    @PostMapping("/userface")
    public ResponseResult updateFace(MultipartFile file, Integer userId, Authentication authentication){
        return userInfoService.updateUserFace(file,userId);
    }
}
